/**
 * Copyright (c) 2014, 2017, Oracle and/or its affiliates.
 * The Universal Permissive License (UPL), Version 1.0
 */
"use strict";
/*
 Copyright 2013 jQuery Foundation and other contributors
 Released under the MIT license.
 http://jquery.org/license
*/
define(["ojs/ojcore","jquery","knockout","ojs/ojdatasource-common"],function(a,g,b){a.uc=function(a){this.data=a;this.current=0;this.Init();this.IW(10)};o_("ArrayPagingDataSource",a.uc,a);a.b.sa(a.uc,a.Fm,"oj.ArrayPagingDataSource");a.uc.prototype.Init=function(){a.uc.u.Init.call(this)};a.b.g("ArrayPagingDataSource.prototype.Init",{Init:a.uc.prototype.Init});a.uc.prototype.UT=function(){return this.nn()?this.Zq:this.totalSize()-this.current};a.uc.prototype.fw=function(a){a=a||{};this.ni=Array(this.UT());
for(var b=0;b<this.ni.length;b++)this.ni[b]=this.data[this.current+b];this.xE();this.Qk=this.oa+this.ni.length-1;a.silent||this.handleEvent("sync",{data:this.ni,startIndex:this.current})};a.uc.prototype.xE=function(){if(void 0!==this.Tn){this.Tn.removeAll();for(var a=0;a<this.ni.length;a++)this.Tn.push(this.ni[a])}};a.uc.prototype.handleEvent=function(b,d){return a.uc.u.handleEvent.call(this,b,d)};a.uc.prototype.nr=function(){return this.ni};a.b.g("ArrayPagingDataSource.prototype.getWindow",{nr:a.uc.prototype.nr});
a.uc.prototype.BF=function(){void 0===this.Tn&&(this.Tn=b.observableArray(),this.xE());return this.Tn};a.b.g("ArrayPagingDataSource.prototype.getWindowObservable",{BF:a.uc.prototype.BF});a.uc.prototype.getPage=function(){return this.ge};a.b.g("ArrayPagingDataSource.prototype.getPage",{getPage:a.uc.prototype.getPage});a.uc.prototype.setPage=function(b,d){d=d||{};b=parseInt(b,10);try{a.uc.u.handleEvent.call(this,a.bd.O.BEFOREPAGE,{page:b,previousPage:this.ge})}catch(e){return Promise.reject(null)}this.pageSize=
null!=d.pageSize?d.pageSize:this.pageSize;d.startIndex=b*this.pageSize;var f=this.ge;this.ge=b;this.oa=d.startIndex;var g=this;return new Promise(function(b,c){g.Gg(d).then(function(){a.uc.u.handleEvent.call(g,a.bd.O.PAGE,{page:g.ge,previousPage:f});b(null)},function(){g.ge=f;g.oa=g.ge*g.pageSize;c(null)})})};a.b.g("ArrayPagingDataSource.prototype.setPage",{setPage:a.uc.prototype.setPage});a.uc.prototype.getStartItemIndex=function(){return this.oa};a.b.g("ArrayPagingDataSource.prototype.getStartItemIndex",
{getStartItemIndex:a.uc.prototype.getStartItemIndex});a.uc.prototype.getEndItemIndex=function(){return this.Qk};a.b.g("ArrayPagingDataSource.prototype.getEndItemIndex",{getEndItemIndex:a.uc.prototype.getEndItemIndex});a.uc.prototype.getPageCount=function(){var a=this.totalSize();return-1==a?-1:Math.ceil(a/this.pageSize)};a.b.g("ArrayPagingDataSource.prototype.getPageCount",{getPageCount:a.uc.prototype.getPageCount});a.uc.prototype.fetch=function(a){a=a||{};if(void 0!==a.pageSize&&void 0!==a.startIndex){if(!this.nn())return Promise.resolve();
this.Zq=a.startIndex+a.pageSize}this.fw(null);return Promise.resolve()};a.b.g("ArrayPagingDataSource.prototype.fetch",{fetch:a.uc.prototype.fetch});a.uc.prototype.Gg=function(a){var b=a||{};void 0!==b.startIndex&&(this.current=b.startIndex);void 0!==b.pageSize&&(this.Zq=this.pageSize=b.pageSize);this.fw(a);return Promise.resolve({data:this.ni,startIndex:this.current})};a.uc.prototype.nn=function(){return this.current+this.Zq<this.totalSize()};a.uc.prototype.IW=function(a){this.Zq=this.pageSize=a;
this.fw(null)};a.uc.prototype.totalSize=function(){return this.data.length};a.uc.prototype.totalSizeConfidence=function(){return"actual"};a.b.g("ArrayPagingDataSource.prototype.totalSizeConfidence",{totalSizeConfidence:a.uc.prototype.totalSizeConfidence});a.uc.prototype.getCapability=function(){return null};a.b.g("ArrayPagingDataSource.prototype.getCapability",{getCapability:a.uc.prototype.getCapability})});